/*****************************************************************************/
/**
 *	\file	Count.h
 *	\author	Xavier
 *	\date	2023/05/07
 *	\version	1.0
 *	\brief	程序的头文件
 *	\note	Copyright (c) 2020-2030 南京理工大学
 *	\remarks	无
 ******************************************************************************/
#ifndef HEAD_H // 防止头文件被重复引用
#define HEAD_H
#include <iostream>
#include <string.h>
#include <windows.h>
#include <string>
#include <direct.h>
#include <stdarg.h>
#include <assert.h>
using namespace std;

struct Room // 存储房间信息
{
	int number;
	int dank;
	int price;
	int state;
};

class P
{
public:
	virtual char *get_name() = 0;
	virtual char *get_ID() = 0;
};

class Pname : virtual public P
{
protected:
	char name[10];
};

class PID : virtual public P
{
protected:
	char ID[19];
};

class Customer : public Pname, public PID // 存储客户的信息
{
public:
	Customer();
	Customer(char *name, char *ID);

	void set_name(char *n) { strcpy(name, n); }
	void set_ID(char *p) { strcpy(ID, p); }
	void set_room_number(int n) { room_number = n; }
	void set_day(int d) { day = d; }
	void set_prepaid(int p) { prepaid = p; }
	char *get_name() { return name; }
	char *get_ID() { return ID; }
	int get_room_number() { return room_number; }
	int get_day() { return day; }
	int get_prepaid() { return prepaid; }

	Customer operator=(const Customer &b)
	{
		this->room_number = b.room_number;
		this->prepaid = b.prepaid;
		this->change = b.change;
		this->day = b.day;
		return b;
	}

	virtual ~Customer();

private:
	// char name[10], ID[19];
	int room_number;
	int prepaid;
	int change;
	int day;
};

#define DBNameRoom "data/roomdata.txt"
#define DBNameCustomer "data/customerdata.txt"
#define DBFolder "data"

class CMgr // 管理类，用来管理客户和房间信息，并实现文件的保存与读取
{
public:
	Room room[80];
	Customer *customer[80];
	int i;
	CMgr()
	{
		i = 0;
	}
	void saveData()
	{
		_mkdir(DBFolder);
		// cout << "start save data" << endl;
		FILE *fp = fopen(DBNameCustomer, "w");

		for (int ind = 0; ind < i; ind++)
		{
			fprintf(fp, "%s %s %d %d %d\n",
					customer[ind]->get_name(),
					customer[ind]->get_ID(),
					customer[ind]->get_room_number(),
					customer[ind]->get_prepaid(),
					customer[ind]->get_day());
		}

		fclose(fp);

		FILE *fp2 = fopen(DBNameRoom, "w");

		for (int ind = 0; ind < 80; ind++)
		{
			fprintf(fp2, "%d %d %d %d\n",
					room[ind].number,
					room[ind].dank,
					room[ind].price,
					room[ind].state);
		}

		fclose(fp2);
		cout << "数据保存成功！" << endl;
	}
	void readData()
	{
		// cout << "start read data" << endl;
		FILE *fp = fopen(DBNameCustomer, "r");
		if (fp)
		{
			int i1 = 0;
			while (1)
			{
				char name[10], ID[19];
				int room_number;
				int prepaid;
				int day;
				if (5 != fscanf(fp, "%s %s %d %d %d\n", name, ID, &room_number, &prepaid, &day))
					break;
				customer[i1] = new Customer(name, ID);
				customer[i1]->set_room_number(room_number);
				customer[i1]->set_prepaid(prepaid);
				customer[i1]->set_day(day);
				i1++;
			}
			fclose(fp);
			i = i1;
		}

		FILE *fp2 = fopen(DBNameRoom, "r");
		int i2 = 0;
		if (fp2)
		{
			while (1)
			{
				if (4 != fscanf(fp2, "%d %d %d %d\n",
								&room[i2].number,
								&room[i2].dank,
								&room[i2].price,
								&room[i2].state))
					break;
				i2++;
			}
			fclose(fp2);
		}
		cout << "数据读取成功！" << endl;
	}
};

void initialRoom(CMgr *mgrobj);			   // 初始化80个房间信息
void welcome();							   // 验证用户登陆,登陆成功显示欢迎信息
void enter(CMgr *mgrobj);				   // 选择功能
void bookRoom(CMgr *mgrobj);			   // 订房实现
void checkIn(CMgr *mgrobj);				   // 入住实现
void checkOut(CMgr *mgrobj);			   // 退房实现
void inquire(CMgr *mgrobj);				   // 查询功能
unsigned char isNumber(const string &str); // 判断字符串是否是数字
int inputINT();							   // 输入整数
void inputStr(char *outstr, int len);	   // 输入字符串
void inputStr2(char *outstr1, int len1, char *outstr2, int len2);
char inputChar();	 // 输入单个字符
int fibonaci(int i); // 计算斐波那契数列

#endif // HEAD _H